package com.chase.springboot.controller;

import com.chase.springboot.common.api.ApiResult;
import com.chase.springboot.model.vo.PostVO;
import com.chase.springboot.service.IEsPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/es")
@RestController
public class EsPostController {
    @Autowired
    private IEsPostService IEsPostService;

    @PostMapping(value = "/importAll")
    public ApiResult<Integer> importAllList(){
        int res = IEsPostService.importAll();
        return ApiResult.success(res);
    }
    @GetMapping(value = "/search")
    public ApiResult<Page<PostVO>> search(@RequestParam(required = false)String keyword,
                                          @RequestParam(required = false, defaultValue = "0")Integer pageNum,
                                          @RequestParam(required = false, defaultValue = "5")Integer pageSize){
        //先将数据导入到elasticsearch中
        IEsPostService.importAll();
        Page<PostVO> esBmsPost = IEsPostService.search(keyword, pageNum, pageSize);
        return ApiResult.success(esBmsPost);
    }
}
